import requests
import time
import os

# 使用说明: 按需修改这些参数后直接run即可无需改代码
HOST = 'http://172.168.1.220:8888'
REQUEST_URL = '/finesRecord/add'
PARAMS = {
    'type': 0,
    'userType': 1,
    'userId': 23,
    'bikeCode': 'a12322222323',
    'longitude': 144,
    'latitude': 44,
    'description': 'Your fines 400$'
}

# 左边为key
FILES = [
    ('photos', r'E:\Picture\menhera\26765568@2x.png'),
    ('photos', r'E:\Picture\menhera\26765569@2x.png'),
    ('photos', r'E:\Picture\menhera\26765574@2x.png')
]

HEADERS = {
    "method": "POST",
    "version": "HTTP/1.1",
    "accept": "*/*",
    "accept-encoding": "gzip, deflate",
    "accept-language": "en-US,en;q=0.8,zh-CN;q=0.6,zh;q=0.4",
    "content-type": "application/x-www-form-urlencoded;charset=UTF-8",
    "User-Agent": "Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.1.6)"
}


def login():
    account_data = {
        "userName": "admin",
        "password": "admin123"
    }
    conn = requests.session()
    conn.post("%s/login/login" % HOST, data=account_data, headers=HEADERS)
    return conn


if __name__ == '__main__':
    conn = login()
    time.sleep(1)
    multi_files = list(map(lambda x: (x[0], (os.path.split(x[1])[1], open(x[1], 'rb'))), FILES))
    response = conn.post("%s%s" % (HOST, REQUEST_URL), params=PARAMS, files=multi_files)
    print(response.text)
